import config from '@/config/config.js';
import axios from "axios";

const fixtureRequest = {
    loadFixtureList(searchFixtureList,pageNum,limit,callback){
        let url = config.fixtureUrl + "/fixture/list?pageNum=" + pageNum + "&limit=" + limit;
        if (searchFixtureList.fixtureId){
            url += "&fixtureId=" + searchFixtureList.fixtureId
        }
        if (searchFixtureList.fixtureName){
            url += "&fixtureName=" + searchFixtureList.fixtureName
        }
        if (searchFixtureList.fixtureTypeId){
            url += "&fixtureTypeId=" + searchFixtureList.fixtureTypeId
        }
        if (searchFixtureList.fixtureBrand){
            url += "&fixtureBrand=" + searchFixtureList.fixtureBrand
        }
        if (searchFixtureList.fixtureModel){
            url += "&fixtureModel=" + searchFixtureList.fixtureModel
        }
        if (searchFixtureList.fixtureStatus){
            url += "&fixtureStatus=" + searchFixtureList.fixtureStatus
        }
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data.data)
        })
    },
    loadUpdateInfo(fixtureId,callback){
        let url = config.fixtureUrl + "/fixture/updateInfo?fixtureId=" + fixtureId
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    deleteFixture(fixtureId,callback){
        let url = config.fixtureUrl + "/fixture/delete?fixtureId=" + fixtureId
        axios.delete(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    loadTypeInuse(fixtureTypeId,callback){
        let url = config.fixtureUrl + "/fixture/getUseList?fixtureTypeId=" + fixtureTypeId
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    updateFixture(updateFixture,callback){
        let url = config.fixtureUrl + "/fixture/update"
        axios.put(url,updateFixture,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    insertFixture(insertFixture,callback){
        let url = config.fixtureUrl + "/fixture/insert"
        axios.post(url,insertFixture,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    exeExport(searchFixtureList,pageNum,limit,callback){
        let url = config.fixtureUrl + "/fixture/export?pageNum=" + pageNum + "&limit=" + limit;
        if (searchFixtureList.fixtureId){
            url += "&fixtureId=" + searchFixtureList.fixtureId
        }
        if (searchFixtureList.fixtureName){
            url += "&fixtureName=" + searchFixtureList.fixtureName
        }
        if (searchFixtureList.fixtureTypeId){
            url += "&fixtureTypeId=" + searchFixtureList.fixtureTypeId
        }
        if (searchFixtureList.fixtureBrand){
            url += "&fixtureBrand=" + searchFixtureList.fixtureBrand
        }
        if (searchFixtureList.fixtureModel){
            url += "&fixtureModel=" + searchFixtureList.fixtureModel
        }
        if (searchFixtureList.fixtureStatus){
            url += "&fixtureStatus=" + searchFixtureList.fixtureStatus
        }
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    }
}
export default fixtureRequest;